//
// Created by LiuYou on 2021/12/9.
//

#include <iostream>
#include <cstring>
#include <sys/stat.h>


int main(int argc, char** argv) {
    if (argc < 2) {
        fprintf( stderr, "用法: %s filename\n", basename( argv[0] ));
        return 1;
    }

    struct stat fileStatus;
    int ret = stat( argv[1], &fileStatus );
    if (ret < 0) {
        perror( "stat(): " );
        return 1;
    }

    if (S_ISREG( fileStatus.st_mode )) {
        std::cout << "-: 常规文件" << std::endl;
    } else if (S_ISDIR( fileStatus.st_mode )) {
        std::cout << "d: 目录文件" << std::endl;
    } else if (S_ISSOCK( fileStatus.st_mode )) {
        std::cout << "s: socket文件" << std::endl;
    } else {
        std::cout << "?: 未知的文件, 不再7种文件范围之内" << std::endl;
    }


    return 0;
}
